package com.primecodegen.common.DmObjProp;

/**
 *----------------------------------------------------------
 *----------------------------------------------------------
 * @author Mohammad Awwad
 * Version: v0.0
 * contact: mhmdawwad@gmail.com
 *-----------------------------------------------------------
 *-----------------------------------------------------------
 */
import java.sql.*;
import java.util.*;
import com.primecodegen.common.base.*;
import com.primecodegen.util.*;
import java.util.logging.*;

public class DmObjPropDAO extends BaseDAO {

    protected static String TblName = "Dm_Obj_Prop";
    protected java.sql.Connection dmObjPropConn;
    protected static final Logger logger = Logger.getLogger(DmObjPropDAO.class.getName());

    public DmObjPropDAO() {
        super();
    }

    public int insert(IBaseTable dmObjPropTable) throws Exception {


        final boolean isConnSupplied = (dmObjPropConn != null);
        DmObjPropTable newRecord = (DmObjPropTable) dmObjPropTable;
        int insertValue = ComConstants.UNREALISTIC_INT;
        Connection con = null;
        PreparedStatement PrepSt = null;
        String sInsertSQL = null;
        StringBuffer sbSQL = new StringBuffer();

        if (dmObjPropTable == null) {
            throw new Exception("DAOException in DmObjPropDAO class :dmObjPropTable is Null");
        }
        sInsertSQL = "INSERT INTO " + DmObjPropDAO.TblName + " (";
        try {
            con = isConnSupplied ? dmObjPropConn : ResourceManager.getConnection();

            String sComma = "";
            int iColCount = 0;


            if (!util.isEmpty(newRecord.getID())) {
                iColCount = iColCount + 1;
                sbSQL.append(sComma).append(DmObjPropDBCols.ID);
                sComma = ",";
            }

            if (!util.isEmpty(newRecord.getValue())) {
                iColCount = iColCount + 1;
                sbSQL.append(sComma).append(DmObjPropDBCols.VALUE);
                sComma = ",";
            }

            if (!util.isEmpty(newRecord.getObjectProperties_ID())) {
                iColCount = iColCount + 1;
                sbSQL.append(sComma).append(DmObjPropDBCols.OBJECTPROPERTIES_ID);
                sComma = ",";
            }

            if (!util.isEmpty(newRecord.getDataModelObject_ID())) {
                iColCount = iColCount + 1;
                sbSQL.append(sComma).append(DmObjPropDBCols.DATAMODELOBJECT_ID);
                sComma = ",";
            }


            sbSQL.append(") VALUES (");
            sComma = "";
            for (int i = 0; i < iColCount; i++) {
                sbSQL.append(sComma).append("?");
                sComma = ",";
            }
            sbSQL.append(");");

            sInsertSQL = sInsertSQL + sbSQL.toString();

            PrepSt = con.prepareStatement(sInsertSQL,
                    Statement.RETURN_GENERATED_KEYS);
            int i = 1;



            if (!util.isEmpty(newRecord.getID())) {
                PrepSt.setInt(i++, newRecord.getID());
            }

            if (!util.isEmpty(newRecord.getValue().trim())) {
                PrepSt.setString(i++, newRecord.getValue().trim());
            }

            if (!util.isEmpty(newRecord.getObjectProperties_ID())) {
                PrepSt.setInt(i++, newRecord.getObjectProperties_ID());
            }

            if (!util.isEmpty(newRecord.getDataModelObject_ID())) {
                PrepSt.setInt(i++, newRecord.getDataModelObject_ID());
            }


            insertValue = PrepSt.executeUpdate();
            ResultSet rsIDJustInserted = PrepSt.getGeneratedKeys();
            if (rsIDJustInserted.next()) {
                insertValue = rsIDJustInserted.getInt(1);
            }



        } catch (SQLException sqlEx) {
            logger.log(Level.WARNING, "SQLException in DmObjPropDAO.insert method Message: {0}", sqlEx.getMessage());
            throw new Exception("SQLException in DmObjPropDAO.insert method");
        } catch (Exception e) {
            logger.log(Level.WARNING, "Exception in DmObjPropDAO.insert method Message: {0}", e.getMessage());
            throw new Exception("Exception in DmObjPropDAO.insert method");
        } finally {
            ResourceManager.close(PrepSt);
            if (!isConnSupplied) {
                ResourceManager.close(con);
            }
        }

        return insertValue;
    }

    public int deleteByID(int IDPar) throws Exception {

        final boolean isConnSupplied = (dmObjPropConn != null);
        int ID = (int) IDPar;
        Connection con = null;
        PreparedStatement stmnt = null;
        int noOfRowsDeleted = ComConstants.UNREALISTIC_INT;
        String deleteSQL = "DELETE FROM " + DmObjPropDAO.TblName + " WHERE " + DmObjPropDBCols.ID + " = ?";
        try {
            con = isConnSupplied ? dmObjPropConn : ResourceManager.getConnection();
            stmnt = con.prepareStatement(deleteSQL);
            stmnt.setInt(1, ID);

            noOfRowsDeleted = stmnt.executeUpdate();



        } catch (SQLException sqlEx) {
            logger.log(Level.WARNING, "SQLException in DmObjPropDAO.DeleteByID method Message: {0}", sqlEx.getMessage());
            throw new Exception("SQLException in DmObjPropDAO.deleteByID method"
                    + sqlEx.getMessage());
        } catch (Exception e) {
            logger.log(Level.WARNING, "Exception in DmObjPropDAO.DeleteByID method Message: {0}", e.getMessage());
            throw new Exception("Exception in DmObjPropDAO.deleteByID method"
                    + e.getMessage());
        } finally {
            if (!isConnSupplied) {
                ResourceManager.close(con);
            }
        }
        return noOfRowsDeleted;
    }

    public int updateByCriterion(IBaseTable dmObjPropSrchCriterionDTOPar,
            IBaseTable updatedRecordPar) throws Exception {

        final boolean isConnSupplied = (dmObjPropConn != null);
        DmObjPropTable dmObjPropSrchCriterionDTO = (DmObjPropTable) dmObjPropSrchCriterionDTOPar;
        DmObjPropTable updatedRecord = (DmObjPropTable) updatedRecordPar;
        int iNoOfRecordsUpdated = -1;
        Connection con = null;
        PreparedStatement stmnt = null;
        try {

            con = isConnSupplied ? dmObjPropConn : ResourceManager.getConnection();
            StringBuffer sbUpdateSQLStmnt = new StringBuffer();
            String sComma = "";
            sbUpdateSQLStmnt.append("UPDATE ").append(DmObjPropDAO.TblName).append(" SET ");



            if (!util.isEmpty(updatedRecord.getID())) {
                sbUpdateSQLStmnt.append(sComma).append(DmObjPropDBCols.ID + " = ").append("?");
                sComma = ",";
            }

            if (!util.isEmpty(updatedRecord.getValue())) {
                sbUpdateSQLStmnt.append(sComma).append(DmObjPropDBCols.VALUE + " = ").append("?");
                sComma = ",";
            }

            if (!util.isEmpty(updatedRecord.getObjectProperties_ID())) {
                sbUpdateSQLStmnt.append(sComma).append(DmObjPropDBCols.OBJECTPROPERTIES_ID + " = ").append("?");
                sComma = ",";
            }

            if (!util.isEmpty(updatedRecord.getDataModelObject_ID())) {
                sbUpdateSQLStmnt.append(sComma).append(DmObjPropDBCols.DATAMODELOBJECT_ID + " = ").append("?");
                sComma = ",";
            }


            sbUpdateSQLStmnt.append(getUpdateWhereClause(dmObjPropSrchCriterionDTO));

            stmnt = con.prepareStatement(sbUpdateSQLStmnt.toString());
            int i = 1;

            if (!util.isEmpty(updatedRecord.getID())) {
                stmnt.setInt(i++, updatedRecord.getID());
            }

            if (!util.isEmpty(updatedRecord.getValue())) {
                stmnt.setString(i++, updatedRecord.getValue());
            }

            if (!util.isEmpty(updatedRecord.getObjectProperties_ID())) {
                stmnt.setInt(i++, updatedRecord.getObjectProperties_ID());
            }

            if (!util.isEmpty(updatedRecord.getDataModelObject_ID())) {
                stmnt.setInt(i++, updatedRecord.getDataModelObject_ID());
            }



            iNoOfRecordsUpdated = stmnt.executeUpdate();

        } catch (Exception e) {
            logger.log(Level.WARNING, "Exception in DmObjPropDAO.updateByCriterion method Message: {0}", e.getMessage());
            throw new Exception(
                    "Exception in DmObjPropDAO.updateByCriterion method ");
        } finally {
            if (!isConnSupplied) {
                ResourceManager.close(con);
            }
        }

        return iNoOfRecordsUpdated;
    }

    public int updateByID(IBaseTable newRecordPar) throws Exception {
        DmObjPropTable newRecord = (DmObjPropTable) newRecordPar;
        if (newRecord != null) {
            DmObjPropTable contentsCategorySrchCriterionDTO = new DmObjPropTable();
            contentsCategorySrchCriterionDTO.setID(newRecord.getID());
            return this.updateByCriterion(contentsCategorySrchCriterionDTO, newRecord);
        } else {
            logger.log(Level.WARNING, "Exception in method DmObjPropDAO.update.newRecord passed is null.");
            throw new Exception(
                    "Exception in method DmObjPropDAO.update.newRecord passed is null.");
        }
    }

    private String getUpdateWhereClause(DmObjPropTable dmObjPropSrchCriterionDTO) {
        String sWhere = "";
        if (dmObjPropSrchCriterionDTO.getID() != ComConstants.UNREALISTIC_INT) {
            sWhere = " WHERE ID = " + dmObjPropSrchCriterionDTO.getID();
        }
        return sWhere;
    }

    public IBaseTable getByID(int ID) throws Exception {

        if (!util.isEmpty(ID)) {
            DmObjPropTable dmObjPropSrchCriterionDTO = new DmObjPropTable();
            dmObjPropSrchCriterionDTO.setID(ID);
            dmObjPropSrchCriterionDTO.setFilter(true);
            ArrayList<DmObjPropTable> dmObjPropTables = this.getByCriterionOrderedBy(
                    dmObjPropSrchCriterionDTO, null);
            DmObjPropTable dmObjPropTable = null;
            if (dmObjPropTables != null) {
                Iterator<DmObjPropTable> it = dmObjPropTables.iterator();
                while (it.hasNext()) {
                    dmObjPropTable = (DmObjPropTable) it.next();
                }
            }

            return dmObjPropTable;
        } else {
            logger.log(Level.WARNING, "Exception in method DmObjPropDAO.getByID.ID passed is unrealistic.");
            throw new Exception(
                    "Exception in method DmObjPropDAO.getByID.ID passed is unrealistic.");
        }
    }
    public ArrayList<DmObjPropTable> getByDataModelObjID(int dataModelObjID) throws Exception {

        if (!util.isEmpty(dataModelObjID)) {
            DmObjPropTable dmObjPropSrchCriterionDTO = new DmObjPropTable();
            dmObjPropSrchCriterionDTO.setDataModelObject_ID(dataModelObjID);
            dmObjPropSrchCriterionDTO.setFilter(true);
            ArrayList<DmObjPropTable> dmObjPropTables = this.getByCriterionOrderedBy(
                    dmObjPropSrchCriterionDTO, null);
           

            return dmObjPropTables;
        } else {
            logger.log(Level.WARNING, "Exception in method DmObjPropDAO.getByID.ID passed is unrealistic.");
            throw new Exception(
                    "Exception in method DmObjPropDAO.getByID.ID passed is unrealistic.");
        }
    }

    public boolean deleteObjectPropertiesIsSafe(int ObjectPropertiesID) throws Exception {
        ArrayList<DmObjPropTable> dmObjPropTables = new ArrayList<DmObjPropTable>();
        if (!util.isEmpty(ObjectPropertiesID)) {
            DmObjPropTable dmObjPropSrchCriterionDTO = new DmObjPropTable();
            dmObjPropSrchCriterionDTO.setObjectProperties_ID(ObjectPropertiesID);
            dmObjPropSrchCriterionDTO.setFilter(true);
            dmObjPropTables = this.getByCriterionOrderedBy(dmObjPropSrchCriterionDTO, null);

            if (dmObjPropTables.size() > 0) {
                return false;//Delete is SAFE, Group Empty
            } else {
                return true;
            }

        } else {
            logger.log(Level.WARNING, "Exception in method DmObjPropDAO.getByID.ID passed is unrealistic.");
            throw new Exception(
                    "Exception in method DmObjPropDAO.getByID.ID passed is unrealistic.");
        }
    }

    public boolean deleteDataModelObjectIsSafe(int dataModelObjectID) throws Exception {
        ArrayList<DmObjPropTable> dmObjPropTables = new ArrayList<DmObjPropTable>();
        if (!util.isEmpty(dataModelObjectID)) {
            DmObjPropTable dmObjPropSrchCriterionDTO = new DmObjPropTable();
            dmObjPropSrchCriterionDTO.setDataModelObject_ID(dataModelObjectID);
            dmObjPropSrchCriterionDTO.setFilter(true);
            dmObjPropTables = this.getByCriterionOrderedBy(dmObjPropSrchCriterionDTO, null);

            if (dmObjPropTables.size() > 0) {
                return false;//Delete is SAFE, Group Empty
            } else {
                return true;
            }

        } else {
            logger.log(Level.WARNING, "Exception in method DmObjPropDAO.getByID.ID passed is unrealistic.");
            throw new Exception(
                    "Exception in method DmObjPropDAO.getByID.ID passed is unrealistic.");
        }
    }

    public ArrayList<DmObjPropTable> getByCriterionOrderedBy(
            IBaseTable dmObjPropSrchCriterionDTOPar, ColToOrderBy colToOrderBy)
            throws Exception {


        final boolean isConnSupplied = (dmObjPropConn != null);
        DmObjPropTable dmObjPropSrchCriterionDTO = (DmObjPropTable) dmObjPropSrchCriterionDTOPar;
        Connection con = null;
        PreparedStatement stmnt = null;
        ResultSet rs = null;

        String sWhereClause = "";

        String sOrderBy = "";
        if (colToOrderBy != null && colToOrderBy.Name != null) {
            sOrderBy = this.getOrderBy(colToOrderBy);
        }
        if (dmObjPropSrchCriterionDTO != null && dmObjPropSrchCriterionDTO.isFilter()) {
            try {
                sWhereClause = this.getRetrieveWhereClause(dmObjPropSrchCriterionDTO);
            } catch (Exception e) {
                System.out.println("getByCriterionOrderedBy.Exception..");
                throw new Exception(" DmObjProp.getByCriterionOrderedBy.Exception:  " + e.getMessage());
            }

            if (sWhereClause != null && !sWhereClause.trim().equalsIgnoreCase("")) {
                sWhereClause = " WHERE " + sWhereClause;
            }
        }
        ArrayList<DmObjPropTable> dmObjPropTables = new ArrayList<DmObjPropTable>();

        try {
            con = isConnSupplied ? dmObjPropConn : ResourceManager.getConnection();

            // String sSelectSQL = "SELECT * FROM   " + TblName;
            StringBuilder sSelectSQL = new StringBuilder();
            sSelectSQL //--
                    .append("SELECT ")//--
                    .append("  dm_obj_prop.ID ").append(" AS ").append(DmObjPropDBCols.ID)//--
                    .append(", dm_obj_prop.Value ").append(" AS ").append(DmObjPropDBCols.VALUE)//--
                    .append(", dm_obj_prop.DataModelObject_ID ").append(" AS ").append(DmObjPropDBCols.DATAMODELOBJECT_ID)//--
                    .append(", dm_obj_prop.ObjectProperties_ID ").append(" AS ").append(DmObjPropDBCols.OBJECTPROPERTIES_ID)//--
                    .append(", object_properties.Code ").append(" AS ").append(DmObjPropDBCols.OBJ_PROP_CODE)//--
                    .append(", object_properties.Type ").append(" AS ").append(DmObjPropDBCols.OBJ_PROP_TYPE)//--
                    .append(", object_properties.Descr ").append(" AS ").append(DmObjPropDBCols.OBJ_PROP_DESCR)//--
                    .append(", data_model_object.Code ").append(" AS ").append(DmObjPropDBCols.DM_OBJ_CODE)//--
                    .append(" FROM ")//--
                    .append(" object_properties ")//--
                    .append("INNER JOIN dm_obj_prop ON (object_properties.ID = dm_obj_prop.ObjectProperties_ID) ")//--
                    .append("INNER JOIN data_model_object ON (dm_obj_prop.DataModelObject_ID = data_model_object.ID)");
            stmnt = con.prepareStatement(sSelectSQL + sWhereClause + sOrderBy);




            if (dmObjPropSrchCriterionDTO != null && dmObjPropSrchCriterionDTO.isFilter()) {
                int colCount = 1;


                if (!util.isEmpty(dmObjPropSrchCriterionDTO.getID())) {
                    stmnt.setInt(colCount++, dmObjPropSrchCriterionDTO.getID());
                }

                if (!util.isEmpty(dmObjPropSrchCriterionDTO.getValue())) {
                    stmnt.setString(colCount++, dmObjPropSrchCriterionDTO.getValue());
                }

                if (!util.isEmpty(dmObjPropSrchCriterionDTO.getObjectProperties_ID())) {
                    stmnt.setInt(colCount++, dmObjPropSrchCriterionDTO.getObjectProperties_ID());
                }

                if (!util.isEmpty(dmObjPropSrchCriterionDTO.getDataModelObject_ID())) {
                    stmnt.setInt(colCount++, dmObjPropSrchCriterionDTO.getDataModelObject_ID());
                }

            }

            rs = stmnt.executeQuery();
            DmObjPropTable dmObjPropTable = null;

            while (rs.next()) {
                dmObjPropTable = new DmObjPropTable();



                dmObjPropTable.setID(rs.getInt(DmObjPropDBCols.ID));
                dmObjPropTable.setValue(util.removeNullFrom(rs.getString(DmObjPropDBCols.VALUE)));
                dmObjPropTable.setObjectProperties_ID(rs.getInt(DmObjPropDBCols.OBJECTPROPERTIES_ID));
                dmObjPropTable.setDataModelObject_ID(rs.getInt(DmObjPropDBCols.DATAMODELOBJECT_ID));

                dmObjPropTable.setObjPropCode(rs.getString(DmObjPropDBCols.OBJ_PROP_CODE));
                dmObjPropTable.setObjPropType(rs.getString(DmObjPropDBCols.OBJ_PROP_TYPE));
                dmObjPropTable.setObjPropDescr(rs.getString(DmObjPropDBCols.OBJ_PROP_DESCR));
                dmObjPropTable.setDmObjCode(rs.getString(DmObjPropDBCols.DM_OBJ_CODE));


                dmObjPropTables.add(dmObjPropTable);
                dmObjPropTable = null;
            }

        } catch (SQLException sqlEx) {
            logger.log(Level.WARNING, "SQLException in DmObjPropDAO.insert method Message: {0}", sqlEx.getMessage());
            throw new Exception(
                    "SQLException in method:DmObjPropDAO.getByCriterionOrderedBy"
                    + sqlEx.getMessage());
        } catch (Exception e) {
            logger.log(Level.WARNING, "Exception in DmObjPropDAO.insert method Message: {0}", e.getMessage());
            throw new Exception(
                    "Exception in method:DmObjPropDAO.getByCriterionOrderedBy"
                    + e.getMessage());
        } finally {
            if (!isConnSupplied) {
                ResourceManager.close(con);
            }
        }
        return dmObjPropTables;
    }

    private String getRetrieveWhereClause(DmObjPropTable dmObjPropSrchCriterionDTO)
            throws Exception {


        StringBuffer sbWhereClause = new StringBuffer();
        String sAnd = "";
        boolean bPrevColExistsInWhereClause = false;
        boolean bAtLeastOneFieldExists = false;

        if (!util.isEmpty(dmObjPropSrchCriterionDTO.getID())) {
            bAtLeastOneFieldExists = true;
            sbWhereClause.append(" dm_obj_prop.ID =").append(" ? ");
            bPrevColExistsInWhereClause = true;
        }

        if (dmObjPropSrchCriterionDTO.Opr != null) {




            if (!util.isEmpty(dmObjPropSrchCriterionDTO.Opr.getValueOpr().trim()) && !util.isEmpty(dmObjPropSrchCriterionDTO.getValue().trim())) {
                bAtLeastOneFieldExists = true;
                if (bPrevColExistsInWhereClause) {
                    sAnd = " AND ";
                } else {
                    sAnd = "";
                }
                if (dmObjPropSrchCriterionDTO.Opr.getValueOpr().trim().equalsIgnoreCase("LIKE")) {
                    sbWhereClause.append(sAnd).append(" " + DmObjPropDBCols.VALUE + " LIKE").append(" ? ");
                } else {
                    sbWhereClause.append(sAnd).append(" " + DmObjPropDBCols.VALUE + "  ").append(dmObjPropSrchCriterionDTO.Opr.getValueOpr().trim()).append("?");
                }
                bPrevColExistsInWhereClause = true;
            }


            if (!util.isEmpty(dmObjPropSrchCriterionDTO.Opr.getObjectProperties_IDOpr().trim()) && !util.isEmpty(dmObjPropSrchCriterionDTO.getObjectProperties_ID())) {
                bAtLeastOneFieldExists = true;
                if (bPrevColExistsInWhereClause) {
                    sAnd = " AND ";
                } else {
                    sAnd = "";
                }
                sbWhereClause.append(sAnd).append(" " + DmObjPropDBCols.OBJECTPROPERTIES_ID + "  ").append(dmObjPropSrchCriterionDTO.Opr.getObjectProperties_IDOpr().trim()).append("?");
                bPrevColExistsInWhereClause = true;
            }


            if (!util.isEmpty(dmObjPropSrchCriterionDTO.Opr.getDataModelObject_IDOpr().trim()) && !util.isEmpty(dmObjPropSrchCriterionDTO.getDataModelObject_ID())) {
                bAtLeastOneFieldExists = true;
                if (bPrevColExistsInWhereClause) {
                    sAnd = " AND ";
                } else {
                    sAnd = "";
                }
                sbWhereClause.append(sAnd).append(" " + DmObjPropDBCols.DATAMODELOBJECT_ID + "  ").append(dmObjPropSrchCriterionDTO.Opr.getDataModelObject_IDOpr().trim()).append("?");
                bPrevColExistsInWhereClause = true;
            }




        }

        if (sbWhereClause.toString().trim().length() <= 0) {
            logger.log(Level.WARNING, "getRetrieveWhereClause Cannot return Null  ");
            throw new Exception("getRetrieveWhereClause Cannot return Null  ");
        } else {
            return sbWhereClause.toString().trim();
        }
    }

    private String getOrderBy(ColToOrderBy colToOrderBy) {
        String sOrderBy = " Order By ";

        sOrderBy = sOrderBy + colToOrderBy.Name;

        if (colToOrderBy.OrderType != null) {
            sOrderBy = sOrderBy + " " + colToOrderBy.OrderType;
        }
        return sOrderBy;
    }

    public int deleteByCriterion(IBaseTable recordsToDeleteCritPar)
            throws Exception {

        final boolean isConnSupplied = (dmObjPropConn != null);
        DmObjPropTable recordsToDeleteCrit = (DmObjPropTable) recordsToDeleteCritPar;
        int iNoOfRecordsDeleted = -1;
        Connection con = null;
        PreparedStatement stmnt = null;

        StringBuffer sbDeleteSQLStmnt = new StringBuffer();
        sbDeleteSQLStmnt.append("DELETE from ").append(DmObjPropDAO.TblName).append(" WHERE ");

        String sWhereClause = "";
        if (recordsToDeleteCrit != null && recordsToDeleteCrit.isFilter()) {
            try {
                sWhereClause = this.getRetrieveWhereClause(recordsToDeleteCrit);
            } catch (Exception e) {
                System.out.println("getByCriterionOrderedBy.Exception..");
                throw new Exception(" DmObjProp.deleteByCriterion.Exception:  "
                        + e.getMessage());
            }

            if (sWhereClause != null
                    && !sWhereClause.trim().equalsIgnoreCase("")) {
                sWhereClause = " WHERE " + sWhereClause;
            }

            sbDeleteSQLStmnt.append(sWhereClause);
        }
        try {
            con = isConnSupplied ? dmObjPropConn : ResourceManager.getConnection();
            stmnt = con.prepareStatement(sbDeleteSQLStmnt.toString());

            if (recordsToDeleteCrit != null && recordsToDeleteCrit.isFilter()) {
            }
            //  iNoOfRecordsDeleted = stmnt.executeUpdate ();



            return iNoOfRecordsDeleted;
        } catch (SQLException sqlEx) {
            logger.log(Level.WARNING, "SQLException in DmObjPropDAO.deleteByCriterion method Message: {0}", sqlEx.getMessage());
            throw new Exception(
                    "SQLException in DmObjPropDAO.deleteByCriterion method");
        } catch (Exception e) {
            logger.log(Level.WARNING, "Exception in DmObjPropDAO.deleteByCriterion method Message: {0}", e.getMessage());
            throw new Exception(
                    "Exception in DmObjPropDAO.deleteByCriterion method");
        } finally {

            if (!isConnSupplied) {
                ResourceManager.close(con);
            }
        }
    }
}
